require(["common", "jQuery", "coAjax", "queryString", "href", "hash_routie"], function(jSouper, $, coAjax, QueryString, href, hash_routie) {
	var _num = 10;
	var _page;
	//分页功能
	hash_routie.on("eva", function() {
		App.set('title', '商品评价');
		var queryString = new QueryString(location.hash);
		_page = 0;
		_load_eval_page(_num, _page);
	});

	function _load_eval_page(num, page) {
		coAjax.get(appConfig.bus.evaluation_with_page_info, {
			num: num,
			page: page
		}, function(result) {
			var info = result.result;
			if (result.result.evaluations.length) {
				console.log("bus.evaluations", info.evaluations);
				App.concat("bus.evaluations", info.evaluations);
				page_info = {
					total_num: info.total_num,
					total_page: info.total_page,
					page: info.page,
					num: info.num
				};
				page_info._number_list = [];
				page_info._number_list.length = info.total_page;
				App.set("$Cache.bus.eval.page_info", page_info);
			} else {
				App.set('moreeva', 'true');
			};
		});
	}
	App.set("$Event.bus.eval.change_page", function(e, vm) {
		_page += 1;
		_load_eval_page(_num, _page);
	});



	//回复评价
	App.set("$Event.eval.reply_eval", function(e, vm) {
		var reply_content = $.trim(vm.get("$Cache.eval.reply_content"));
		if (!reply_content) {
			return
		}
		coAjax.post(appConfig.bus.add_comment, {
			reply_id: vm.get("comment_id"),
			content: reply_content
		}, function(result) {
			var comments = vm.get("comment.comments");
			comments.unshift(result.result);
			vm.set("comment.comments", comments);
			vm.set('$Cache.eval.reply_content', '');
			alert('success', '发表回复成功!');
		}, function(e) {
			alert('error', '网络错误，发表失败');
		});
	});
	//接口实现，回复评论
	App.set("$Event.comment.reply", function(e, vm) {
		var _reply_content = $.trim(vm.get("_reply_content"));
		if (!_reply_content) {
			return
		}
		coAjax.post(appConfig.bus.add_comment, {
			reply_id: vm.get("_id"),
			content: _reply_content
		}, function(result) {
			var comments = vm.get("comments");
			comments.unshift(result.result);
			vm.set("comments", comments)
		});
	});
});